package com.code.web.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.Configuration;

/*
 * @author: liyufei
 * @date: 2018-06-11 9:56
 */
@Configuration
@Aspect
public class MyAop {

    /*
     * 定义一个切入点
     */
    @Pointcut("execution(* com.code.web.controller.IndexController.*(..))")
    public void excudeService() {
        System.out.println("==========定义切点===========");
    }

    /**
     * 通过连接点切入
     */
    @Before("excudeService()")
    public void twiceAsOld1(JoinPoint point) {
        System.out.println("before切面执行了。。。。" + point.getKind());
    }

    @Around("excudeService()")
    public Object twiceAsOld(ProceedingJoinPoint thisJoinPoint) {
        Object s = null;
        try {
            s = thisJoinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("Around切面执行了。。。。");
        return s;
    }

    @After("excudeService()")
    public void twiceAsOld3(JoinPoint point) {
        System.out.println("after切面执行了。。。。" + point.getKind());
    }

    @AfterReturning("excudeService()")
    public void doFindByIdCheck() {
        System.out.println("=======AfterReturning后置通知==================");
    }

}
